Módulo:Cite web
-- -- This module implements Template:Cite web. local p = {} -- Lazily load a mw.language object. local lang local function makeCategoryLink(cat) return string.format('Category:%s', cat) end local function makeWikitextError(msg) local ret = '' ret = ret .. string.format( 'Template:Cite web error: %s.', msg ) if mw.title.getCurrentTitle().namespace 0 then ret = ret .. makeCategoryLink('Pages with template parameter errors') end return ret end local function makeDateLink(date, year) lang = lang or mw.language.getContentLanguage() local success, dateLink = pcall( lang.formatDate, lang, 'F j, Y', date ) if success and dateLink then if year then dateLink = dateLink .. string.format(', %s', year) end return dateLink end end local function makeDate(date, year, month) local ret if date then ret = date elseif year then if month then ret = month .. ' ' .. year else ret = year end end if ret then return string.format(' (%s)', ret) end end local function makeAccessdateBlurb(monthDay, year, yearArgName) year = year or yearArgName return string.format(' Retrieved on %s, %s.', monthDay, year) end function p._main(args) -- Validate input if not args.url or not args.title then return makeWikitextError("parameters url and title must be specified") end if args.archiveurl and not args.archivedate or args.archivedate and not args.archiveurl then return makeWikitextError( "parameters archiveurl and archivedate must be both specified or both omitted" ) end local ret = {} -- Authors if args.author or args.last then local display if args.last then display = args.last if args.first then display = display .. ', ' .. args.first end else display = args.author end if args.authorlink then ret+ 1 = string.format('%s', args.authorlink, display) else ret+ 1 = display end if args.coauthors then ret+ 1 = '; ' .. args.coauthors end ret+ 1 = makeDate(args.date, args.year, args.month) ret+ 1 = '. ' end -- Editor if args.editor then ret+ 1 = ' ' .. args.editor .. ':' end -- URL if args.title then if args.archiveurl then ret+ 1 = string.format('%s', args.archiveurl, args.title) elseif args.url then ret+ 1 = string.format('%s', args.url, args.title) end end -- Language if args.language then ret+ 1 = string.format( ' (%s)', args.language ) end -- Format if args.format then ret+ 1 = string.format(' (%s)', args.format) end -- Work if args.work then ret+ 1 = string.format(". %s", args.work) end -- Pages if args.pages then ret+ 1 = ' ' .. args.pages end -- Publisher if args.publisher then ret+ 1 = '. ' .. args.publisher end -- Add date for when no author is specified. if not args.author and not args.last then ret+ 1 = makeDate(args.date, args.year, args.month) end ret+ 1 = '.' -- Archive date. if args.archivedate then local url = args.url or ' }' local dateLink = makeDateLink(args.archivedate, args.archiveyear) if dateLink then ret+ 1 = string.format( ' Archived from the original on %s.', url, dateLink ) end end -- Access date if args.accessdate then local dateLink = makeDateLink(args.accessdate, args.accessyear) if dateLink then ret+ 1 = string.format(' Retrieved on %s.', dateLink) end elseif args.accessmonthday then ret+ 1 = makeAccessdateBlurb( args.accessmonthday, args.accessyear, ' }' ) elseif args.accessdaymonth then ret+ 1 = makeAccessdateBlurb( args.accessdaymonth, args.accessyear, ' }' ) end -- Quote if args.quote then ret+ 1 = string.format(' "%s"', args.quote) end return table.concat(ret) end function p.main(frame) local args = {} for k, v in pairs(frame:getParent().args) do v = v:match('^%s*(.-)%s*$') -- trim whitespace if v ~= '' then argsk = v end end return p._main(args) end return p --